﻿/// <reference path="../_references.js" />
(function (e) {
    e.viewManager = function (onViewChange) {
        $(window).bind('hashchange', function () {
            var state = $.deparam.fragment();
            onViewChange(state);
        });
    };
    e.viewManager.prototype = {
        changeView: function (viewName, params) {
            if (!viewName)
                throw "ViewName not defined";
            var st = null;
            if (!params)
                st = { view: viewName };
            else
                st = $.extend({}, { view: viewName }, params);
            if (!Object.stateEquals($.deparam.fragment(), st))
                $.bbq.pushState(st, 2);
            else
                $(window).hashchange();
        }
    };
} (this.eg = this.eg || {}));